import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

// 定义路由配置类型
const routes: Array<RouteRecordRaw> = [
    {
        path: "/",
        name: "Home",
        component: () => import(/* webpackChunkName: "home-group" */ "../views/Home.vue"), // 路由懒加载 & 分组
    },
    {
        path: "/about",
        name: "About",
        component: () => import(/* webpackChunkName: "about-group" */ "../views/About.vue"), // 路由懒加载 & 分组
    },
    {
        path: "/demo1",
        name: "demo1",
        component: () => import(/* webpackChunkName: "about-group" */ "../views/demo1.vue"), // 路由懒加载 & 分组
    },
    {
        path: "/demo2",
        name: "demo2",
        component: () => import(/* webpackChunkName: "about-group" */ "../views/demo2.vue"), // 路由懒加载 & 分组
    },
    {
        path: "/demo3",
        name: "demo3",
        component: () => import(/* webpackChunkName: "about-group" */ "../views/demo3.vue"), // 路由懒加载 & 分组
    },
    {
        path: "/demo4",
        name: "demo4",
        component: () => import(/* webpackChunkName: "about-group" */ "../views/demo4.vue"), // 路由懒加载 & 分组
    },
    {
        path: "/demo5",
        name: "demo5",
        component: () => import(/* webpackChunkName: "about-group" */ "../views/demo5.vue"), // 路由懒加载 & 分组
    },


];

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL), // HTML5 History 模式
    routes,
});

// 全局前置守卫
// router.beforeEach((to, from, next) => {
//
//      localStorage.setItem("isLoggedIn","默认登录完成")
//
//     console.log(`Navigating from ${from.fullPath} to ${to.fullPath}`);
//
//     // 模拟权限验证
//     if (to.name === "About" && userIsLoggedIn()) {
//         console.log("User not logged in. Redirecting to Home...");
//         next({ name: "Home" }); // 未登录用户重定向到首页
//     } else {
//         next(); // 允许路由跳转
//     }
// });

// 模拟登录状态检查函数
// function userIsLoggedIn(): boolean {
//     console.log(localStorage.getItem("isLoggedIn"))
//     // 这里可以替换为实际的登录验证逻辑
//     return localStorage.getItem("isLoggedIn") === "true";
// }

export default router;
